﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcmyjobs.Web.Admin
{
    public partial class ListHunterSubmit : System.Web.UI.Page
    {
        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
        DataSet ds;
        int count = 0;
        int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = int.Parse(Application["webid"].ToString());
            if (!IsPostBack)
            {
                if (Session["adminName"] != null)
                {
                    getcout(id);
                    //bindData(); //使用url分页，只需在分页事件处理程序中绑定数据即可，无需在Page_Load中绑定，否则会导致数据被绑定两次
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }

            }


        }
        protected void getcout(int atid)
        {
            ds = bub.PageUserAskHunter(atid, 1, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            this.lbl_count.Text = count.ToString();
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }
        protected void bind(int atid)
        {
            //if (ViewState["page"] != null && ViewState["page"].ToString() != "")
            //    AspNetPager1.CurrentPageIndex = int.Parse(ViewState["page"].ToString());

            ds = bub.PageUserAskHunter(atid, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            this.lbl_count.Text = count.ToString();
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

        }



        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            //ViewState["page"] = AspNetPager1.CurrentPageIndex;
            id = int.Parse(Application["webid"].ToString());
            bind(id);

        }

        //处理中
        protected void lbn_check_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            bub.UpdateAskHunterStatus(idlist, 1);
            id = int.Parse(Application["webid"].ToString());
            bind(id);

        }
        //成功
        protected void lbn_issuccess_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            bub.UpdateAskHunterStatus(idlist, 2);
            id = int.Parse(Application["webid"].ToString());
            bind(id);

        }
        //删除
        protected void lbn_del_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            bub.deleteaskhunters(idlist);
            id = int.Parse(Application["webid"].ToString());
            bind(id);

        }

        public string GetBH(string str)
        {
            return "L"+str.ToString().PadLeft(6, '0');
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)GridView1.Rows[i].FindControl("chku");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
    }
}